<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>

<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" action="" onsubmit="return false" id="comment" style="width: 30%;">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 100px">选择学校</label>
        <div class="layui-input-block">
        <select id="school_id" name="school_id" lay-verify="" style="width: 25%">
            <option value="0">系统通知</option>
            {foreach $school as $data}
                <option value="{$data.school_id}">{$data.school_name}</option>
            {/foreach}
        </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="name" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea id="demo" style="display: none;"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add">立即添加</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use('layedit', function(){
        layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: "{:url('/common/notice')}" //接口url
                ,type: 'post' //默认post
            }
        });
        index = layedit.build('demo',{
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线
                ,'del' //删除线
                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'image' //插入图片
            ]}
        );

        //建立编辑器
        layedit.getContent(index)
    });
</script>
<script>
    $("#add").click(function(){
        var content = layedit.getContent(index);
        var title   = $("#title").val()
        var id = $("#school_id").val();
        if(!id){
            alert("学校不能为空");return false;
        }
        $.ajax({
            data:{school_id:id,content:content,name:title},
            type:"post",
            url:"{:url('/schoolNotice/noticeAdd')}",
            dataType:"json",
            beforeSend:function () {
                index = layer.load(2, {time: 100*1000});
            },
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.reload();
                    });
                    layer.close(index);
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    layer.close(index);
                    return;
                }
            }
        })

    })
    //返回
    $("#back").click(function () {
        window.history.go(-1)
    })
</script>